package com.hdl.design.pattern.prototype;

import java.io.Serializable;

/**
 * 类名 ConcretePrototypeFirst
 * 描述 具体克隆对象
 *
 * @author hedonglin
 * @version 1.0
 * @date 2019/9/25 10:54
 */
public class ConcretePrototype implements Cloneable , Serializable {
    private String id;
    private User user;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public ConcretePrototype(String id, User user) {
        this.id = id;
        this.user = user;
    }

    @Override
    protected ConcretePrototype clone() throws CloneNotSupportedException {
        // 浅克隆，直接返回clone方法对象
        return (ConcretePrototype)super.clone();
        // 深克隆，方法一：手动赋值
//        first.setUser(this.user.clone());
//        return first;

        // 深克隆，方法二：实现序列化接口，使用SerializationUtils.clone
//        return SerializedCloneUtils.clone(this);

//       深克隆：方法三：用fastjson从Object转成json，然后转回object，本质上是反射 略
    }
}
